package com.xiaohu.mayi_huiyuan.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class InterceptorConfig implements HandlerInterceptor {

    private final static Logger logger = LoggerFactory.getLogger(Exception.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws ServletException, IOException {
        HttpSession session = request.getSession();
        logger.info("进入拦截器！");
        if (!StringUtils.isEmpty(session.getAttribute("user"))) {
            return true;
        } else {
            response.sendRedirect("/");
        }
        return false;

    }


}
